#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Copyright (c) 2025 粤港澳大湾区（广东）国创中心

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.

File: onCataegorySimulation.py
Desc: Simulation pannel in the application.
Author: xumanjia
Date: 2025-08-01
"""

from PyQt5.QtWidgets import QMessageBox, QWidget, QDialog
from Dialog.PythonMeshDlg import MeshSettingView # type: ignore
from PyQt5.QtCore import Qt
from scripts.Simulation.pyncti_mesh_surface_generation import pyncti_mesh_surface_generation
from scripts.Simulation.pyncti_mesh_add_force import pyncti_mesh_add_force
from scripts.Simulation.pyncti_mesh_add_spc import pyncti_mesh_add_spc
from scripts.Simulation.pyncti_mesh_add_material import pyncti_mesh_add_material
from scripts.Simulation.pyncti_pickup_mesh import pyncti_pickup_mesh
from scripts.Simulation.pyncti_set_visibility_by_sel import pyncti_set_visibility_by_sel
from scripts.Simulation.pyncti_set_visibility_only_show_by_sel import pyncti_set_visibility_only_show_by_sel
from scripts.Simulation.pyncti_set_visibility_all_show import pyncti_set_visibility_all_show
from scripts.Simulation.pyncti_create_volume_mesh import pyncti_create_volume_mesh

def on_mesh_surface_generation(self):
    if False == hasattr(self, 'doc'):
        return
    pyncti_mesh_surface_generation(self.NCTI,self.doc)

def on_mesh_volume_generation(self):
    if False == hasattr(self, 'doc'):
        return
    pyncti_create_volume_mesh(self.NCTI,self.doc)
    
def on_single_force(self):
    if False == hasattr(self, 'doc'):
        return
    sel = self.NCTI.SelectionManager(self.doc)
    if len(sel.CellIDs) == 0:
        QMessageBox.about(self, "提示", f"请先选择网格节点")
        return
    pyncti_mesh_add_force(self.NCTI,self.doc)
    

def on_single_constraint(self):
    if False == hasattr(self, 'doc'):
        return 
    sel = self.NCTI.SelectionManager(self.doc)
    if len(sel.CellIDs) == 0:
        QMessageBox.about(self, "提示", f"请先选择网格节点")
        return
    pyncti_mesh_add_spc(self.NCTI,self.doc)
    

def on_material_properties(self):
    if False == hasattr(self, 'doc'):
        return
    sel = self.NCTI.SelectionManager(self.doc)
    if len(sel.ObjectNames) == 0:
        QMessageBox.about(self, "提示", f"请先选择网格对象")
        return
    pyncti_mesh_add_material(self.NCTI,self.doc)
    
def on_set_pickup_mesh(self, state):
    if False == hasattr(self, 'doc'):
        return
    if state >= 0 and state < 5:
        pyncti_pickup_mesh(self.NCTI,self.doc,state)
    
def on_set_visibility_by_sel(self,bvis):
    if False == hasattr(self, 'view'):
        return
    pyncti_set_visibility_by_sel(self.NCTI,self.view,bvis)

def on_set_visibility_only_show_by_sel(self):
    if False == hasattr(self, 'view'):
        return
    pyncti_set_visibility_only_show_by_sel(self.NCTI,self.view)

def on_set_visibility_all_show(self):
    if False == hasattr(self, 'view'):
        return
    pyncti_set_visibility_all_show(self.NCTI,self.view)
